{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "19f380b8",
   "metadata": {},
   "source": [
    "# 3.5 lambda函数(现在不建议使用)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b8321bbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1,2,3,4,5]\n",
    "def my_apply(fn,arr):\n",
    "    return [fn(x) for x in arr]\n",
    "def sq(x):\n",
    "    return x**2\n",
    "my_apply(sq,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3f247d16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def my_apply(fn,arr):\n",
    "    return [fn(x) for x in arr]\n",
    "my_apply(lambda x: x**2,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "be17cf7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 6]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [1,6,2,3,4]\n",
    "nums.sort()#nums.sort(reverse=True)反向排序\n",
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "eb7ec345",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'name': 'Tom', 'age': 18},\n",
       " {'name': 'Tom', 'age': 18},\n",
       " {'name': 'Tom', 'age': 18}]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "students = [\n",
    "    {'name':'Tom','age':18},\n",
    "    {'name':'Tom','age':18},\n",
    "    {'name':'Tom','age':18}\n",
    "]\n",
    "students\n",
    "studets.sort(）=(key=lambda s: s['age'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e72ddf43",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
